package com.wyj.controller;

import com.wyj.service.impl.YlrcRoleAuthoritiesServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：wyj
 * @description：TODO
 * @date ：2022/11/19 9:12 下午
 */
@RestController
@RequestMapping("/common")
public class CommonController {

    @Autowired
    YlrcRoleAuthoritiesServiceImpl ylrcRoleAuthoritiesServiceImpl;

    //角色删除后，用户自动失去该角色下的菜单权限；
    @DeleteMapping("{/roleId}")
    public String deleteRoleAuByRoleId(@PathVariable("roleId") int roleId) {
        try {
            int i = ylrcRoleAuthoritiesServiceImpl.deleteRoleAuByRoleId(roleId);
            if (i >= 0) return "角色删除后 用户自动失去该角色下的菜单权限失败";
        } catch (Exception e) {
            new RuntimeException(e);
        }

        return "角色删除后 用户自动失去该角色下的菜单权限失败";
    }
    //菜单删除后，角色及用户自动失去改菜单权限。
    @DeleteMapping("{/authoritiesId}")
    public String deleteRoleAuByAuId(@PathVariable("authoritiesId") int authoritiesId) {
        try {
           int i = ylrcRoleAuthoritiesServiceImpl.deleteRoleAuByAuId(authoritiesId);
            if (i >= 0) return "菜单删除后，角色及用户自动失去改菜单权限成功";
        } catch (Exception e) {
            new RuntimeException(e);
        }
        return "菜单删除后，角色及用户自动失去改菜单权限失败";
    }

}
